package mailTools

import (
	"app/pkg/config"
	"app/pkg/log"
	"crypto/tls"

	"gopkg.in/gomail.v2"
)

func SendMail(receive []string, text string) error {
	m := gomail.NewMessage()
	m.SetHeader(`From`, config.Config.Mail.Sender)
	m.SetHeader(`To`, receive...)
	m.SetHeader(`Subject`, config.Config.Mail.Title)
	m.SetBody(`text/html`, text)
	d := gomail.NewDialer(config.Config.Mail.SmtpAddr, config.Config.Mail.SmtpPort, config.Config.Mail.Sender, config.Config.Mail.AuthorizationCode)
	d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
	if err := d.DialAndSend(m); err != nil {
		log.ErrorByKv("send mail error", "err", err.Error())
		return err
	}
	return nil
}
